package com.ruoyi.security.controller;

import com.ruoyi.common.core.domain.R;
/*import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.bean.BeanUtils;*/
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.omp.api.RemoteTrendService;
/*import com.ruoyi.security.domain.AfElevator;
import com.ruoyi.security.domain.AfElevatorMaintenance;
import com.ruoyi.security.domain.AfMaintenance;
import com.ruoyi.security.domain.InspectionRecord;
import com.ruoyi.security.domain.vo.AfElevatorMaintenanceBPVo;
import com.ruoyi.security.domain.vo.AfElevatorOnlineRateBPVo;
import com.ruoyi.security.service.*;*/
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Api(tags = "大屏-智慧安防")
@RestController
@RequestMapping("/dp_security")
public class DPSecurityController extends BaseController {
    //todo
/*    @Autowired
    private IAfElevatorService afElevatorService;

    @Autowired
    private IAfElevatorErrorService afElevatorErrorService;

    @Autowired
    private IAfElevatorRepairService afElevatorRepairService;

    @Autowired
    private IInspectionRecordService inspectionRecordService;

    @Autowired
    private IAfElevatorMaintenanceService afElevatorMaintenanceService;

    //设备维保
    @Autowired
    private IAfMaintenanceService afMaintenanceService;*/

    @Autowired
    private RemoteTrendService remoteTrendService;

    // dp_security_summary

    @ApiOperation(value="BP-智慧安防-今日安防概述", notes="智慧安防-今日安防概述")
    @GetMapping(value = "/dp_security_summary")
    public AjaxResult dp_security_summary(@RequestParam(value = "parkNum",required = false) String parkNum) {
        String trendType = "dp_security_summary";
        R remote = remoteTrendService.getTrendDataByType(trendType,-1);
        Map<String,String> result = (Map<String,String>)remote.getData();

        return AjaxResult.success(result);
    }

    @ApiOperation(value="BP-智慧安防-今日安防概述", notes="智慧安防-今日安防概述")
    @GetMapping(value = "/dp_security_special_device")
    public AjaxResult dp_security_special_device(){
        String trendType = "dp_security_special_device";
        R remote = remoteTrendService.getTrendDataByType(trendType,-1);
        Map<String,String> result = (Map<String,String>)remote.getData();

        return AjaxResult.success(result);
    }
    //
/*    @ApiOperation(value="BP-防疫来访登记", notes="防疫来访登记")
    @GetMapping(value = "/special_elevator_detail")
    public AjaxResult special_elevator_detail1() {
        String sql = "select elevator_code,elevator_name,location,state from omp_af_elevator group by state,elevator_code";
        R remote = remoteTrendService.execSql(sql);
        return AjaxResult.success(remote.getData());
    }*/

    //
    @ApiOperation(value="BP-特种设备-电梯详情", notes="特种设备-电梯详情")
    @GetMapping(value = "/special_elevator_detail")
    public AjaxResult special_elevator_detail() {
        String sql = "select elevator_code,elevator_name,location,state from omp_af_elevator group by state,elevator_code";
        R remote = remoteTrendService.execSql(sql);
        return AjaxResult.success(remote.getData());
    }

/**
     * 电梯故障类型占比


    @ApiOperation(value="电梯故障类型占比-大屏", notes="电梯故障类型占比")
    @GetMapping("/faltRatio")
    public AjaxResult ratio() {
        return AjaxResult.success(afElevatorErrorService.getTypeRatio());
    }

*//*
*
     * 查询电梯维修次数

*//*

    @ApiOperation(value="大屏查询电梯维修次数", notes="大屏查询电梯维修次数")
    @GetMapping("/countMonth")
    public AjaxResult countMonth(String month) {
        Map<String,Integer> list = afElevatorRepairService.selectAfElevatorRepairByMonth(month);
        return AjaxResult.success(list);
    }

*//*
*
     * 大屏查询电梯维保记录,暂时直接调用电梯维保接口

*//*

    @ApiOperation(value = "大屏电梯维保记录", notes = "大屏电梯维保记录")
    @GetMapping("/listBP1")
    public AjaxResult listBP(AfElevatorMaintenance afElevatorMaintenance) {
        return listBPFromLocal(afElevatorMaintenance);
    }

    //从线上同步的维保工单
    private AjaxResult listBPFromOnline(AfElevatorMaintenance afElevatorMaintenance){
        startPage();
        List<AfElevatorMaintenance> list = afElevatorMaintenanceService.selectAfElevatorMaintenanceList(afElevatorMaintenance);
        List<AfElevatorMaintenanceBPVo> result = new ArrayList<>();
        list.stream().forEach(o -> {
            AfElevatorMaintenanceBPVo a = new AfElevatorMaintenanceBPVo();
            BeanUtils.copyBeanProp(o, a);
            AfElevatorMaintenance last = afElevatorMaintenanceService.selectLastAfElevatorMaintenance(o);
            //String 转 date
            a.setLastUpkeepDate(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,last.getUpkeepDate()));
            result.add(a);
        });
        return AjaxResult.success(result);
    }

    //从本地数据 omp_af_maintenance表分析
    private AjaxResult listBPFromLocal(AfElevatorMaintenance afElevatorMaintenance){
        startPage();
        AfMaintenance maintenance = new AfMaintenance();
        maintenance.setDeviceCategory("电梯设备");
        List<AfMaintenance> list = afMaintenanceService.selectAfMaintenanceList(maintenance);
        List<AfElevatorMaintenanceBPVo> result = new ArrayList<>();
        list.stream().forEach(o -> {
            AfElevatorMaintenanceBPVo a = new AfElevatorMaintenanceBPVo();
            a.setAliasOfAddress(o.getDeviceAddr());
            if(o.getDeviceName().endsWith("货梯")){
                a.setElevatorType("货梯");
            }else{
                a.setElevatorType("客梯");
            }
            a.setUpkeepDate(o.getMaintenanceDate());
            a.setMaintenanceType(o.getMaintenanceType());
            a.setMaintenanceMan(o.getMaintenanceMan());
            //AfMaintenance last = afMaintenanceService.selectLastAfMaintenance(o);
//            if(last != null){
//                a.setLastUpkeepDate(last.getMaintenanceDate());
//            }
            result.add(a);
        });
        return AjaxResult.success(result);
    }

*//*
*
     * 控制中心-智慧安防-巡更任务,当天时间，按编码查询 todo

*//*

    @ApiOperation(value="大屏控制中心-智慧安防-巡更任务", notes="大屏控制中心-智慧安防-巡更任务")
    @GetMapping("/listBP3")
    public AjaxResult getInfo(InspectionRecord inspectionRecord) {
        startPage();
        List<InspectionRecord> list = inspectionRecordService.selectInspectionRecordList(inspectionRecord);
        return AjaxResult.success(list);
    }




    // 大屏获取电梯实时数据
    @ApiOperation(value = "获取电梯实时数据", notes = "获取电梯实时数据")
    @GetMapping(value = "/realData/{id}")
    public AjaxResult getRealData(@PathVariable("id") String id) {
        return AjaxResult.success(afElevatorService.getElevatorRealData(id));
    }*/
}
